package com.anntly.netty.protocoltcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @Auther: 张文
 * @Date: 2020/6/14 18:45
 * @Description:
 */
public class MyEncoder extends MessageToByteEncoder<MessageProtocol> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, MessageProtocol messageProtocol, ByteBuf byteBuf) throws Exception {
        System.out.println("调用Encoder");
        int len = messageProtocol.getLen();
        byte[] content = messageProtocol.getContent();
        byteBuf.writeInt(len);
        byteBuf.writeBytes(content);
    }
}
